package com.enotourister.core.proposal;

import com.enotourister.core.model.Contract;
import com.enotourister.core.provider.Provider;
import com.enotourister.core.rfp.RequestForProposal;

public abstract class Proposal implements java.io.Serializable {
	private static final long serialVersionUID = -1209111550000572857L;
	
	private RequestForProposal rfp = null;
	private Provider provider = null;
	private String proposal = null; //TODO: Make a decent proposal, not a text
	
	public Proposal(String proposal, RequestForProposal rfp, Provider provider) {
		this.rfp = rfp;
		this.proposal = proposal;
		this.provider = provider;
	}

	public String getProposal() {
		return proposal;
	}

	public void setProposal(String proposal) {
		this.proposal = proposal;
	}

	public RequestForProposal getRequestForProposal() {
		return rfp;
	}

	public Provider getProvider() {
		return provider;
	}
	
	@Override
	public String toString() {
		return "[proposal: " + proposal + "," + getRequestForProposal() + "," + getProvider() + "]";
	}
	
	public Contract contract() {
		// Contracting proposal
		Provider provider = getProvider();
		boolean contracted = provider.contractProposal(this);
		Contract contract = null;
		
		if (contracted) {
			contract = makeContract(this);
			
			if (contract !=  null)
				provider.informContract(contract);
			else
				contracted = false;
		}
			
		return contract;
	}

	private Contract makeContract(Proposal proposal){
		// TODO: Save contract
		return new Contract(proposal);
	}
}
